<?php
	global $_W,$_GPC;
	if($_W['role']&&$_W['isajax']){
		$recharge_discount_info = $_GPC['recharge_discount_info'];
		$mcard_level_info = $_GPC['member_level_info'];
		if(!empty($recharge_discount_info)){
			$recharge_discount_info_array = explode('oOo', $recharge_discount_info);
			$discount_arr = '';
			foreach ($recharge_discount_info_array as $key => $v) {
				$arr = explode('||', $v);
				$discount_arr[]= array('condition_money'=>$arr[0],'give_money'=>$arr[1]);
				$discount_arrAy[intval($arr[0])] = array('condition_money'=>$arr[0],'give_money'=>$arr[1]);
			}
		}
		if (!empty($mcard_level_info)) {
			$mcard_level_info_array = explode('oOo',$mcard_level_info);
			$level_arr = '';
			$level_arrAy = array();
			foreach ($mcard_level_info_array as $keys => $l) {
				$arr2 = explode('||', $l);
				$level_arr[] = array('mcard_level_level'=>$arr2[0],'mcard_level_name'=>$arr2[1],'mcard_level_discount'=>$arr2[2],'mcard_level_condition'=>$arr2[3]);
				if(array_key_exists(intval($arr2[0]),$level_arrAy)){
					exit(json_encode(array('status'=>'2','msg'=>'存在重复等级,请检测会员等级名称:'.$arr2[1].'行设置')));
					break;
				}
				$level_arrAy[intval($arr2[0])] = array('mcard_level_level'=>$arr2[0],'mcard_level_name'=>$arr2[1],'mcard_level_discount'=>$arr2[2],'mcard_level_condition'=>$arr2[3]);				
			}
		}
		krsort($level_arrAy);
		krsort($discount_arrAy);
		$status = $_GPC['status'];
		$activation = $_GPC['activation'];
		$activation_money = $_GPC['activation_money'];
		$recharge_discount = $_GPC['recharge_discount'];
		$recharge_discount_info = @serialize($discount_arr);
		$islevel = $_GPC['islevel'];
		$member_level_info = @serialize($level_arr);
		$default_mcard_level_name = $_GPC['default_mcard_level_name'];
		$default_mcard_level_discount = $_GPC['default_mcard_level_discount'];
		$description = $_GPC['description'];
		$data = array(
			'uniacid'=>$_W['uniacid'],
			'status'=>$status,
			'activation'=>$activation,
			'activation_money'=>$activation_money,
			'recharge_discount'=>$recharge_discount,
			'recharge_discount_info'=>$discount_arrAy,
			'islevel'=>$islevel,
			'member_level_info'=>$level_arrAy,
			'default_mcard_level_name'=>$default_mcard_level_name,
			'default_mcard_level_discount'=>$default_mcard_level_discount,
			'description'=>$description 
		);		
		$insdata = array(
			'uniacid'=>$_W['uniacid'],
			'status'=>$status,
			'activation'=>$activation,
			'activation_money'=>$activation_money,
			'recharge_discount'=>$recharge_discount,
			'recharge_discount_info'=>$recharge_discount_info,
			'islevel'=>$islevel,
			'member_level_info'=>$member_level_info,
			'default_mcard_level_name'=>$default_mcard_level_name,
			'default_mcard_level_discount'=>$default_mcard_level_discount,
			'description'=>$description 
		);

		include_once MODULE_ROOT.'/mii/class/mii.class.php';
		$miiclass = new miiclass();
		$miiclass->build_array_php($data,'mcardinfo','/public/mcard/',$_W['uniacid']);				
		$v = pdo_get('mii_ang_mcard_info',array('uniacid'=>$_W['uniacid']),array('id'));
		if(!empty($v)){
			$up = pdo_update('mii_ang_mcard_info',$insdata,array('uniacid'=>$_W['uniacid']));
			if($up){
				exit(json_encode(array('status'=>'1','msg'=>'修改成功')));
			}else{
				exit(json_encode(array('status'=>'2','msg'=>'未做修改')));
			}
		}else{
			$ins = pdo_insert('mii_ang_mcard_info',$insdata);
			if($ins){
				exit(json_encode(array('status'=>'1','msg'=>'保存成功')));
			}else{
				exit(json_encode(array('status'=>'2','msg'=>'保存失败')));
			}			
		}
	}else{
		$code = array('status'=>'2','msg'=>'没有操作权限');
		exit(json_encode($code));
	}



?>